package com.xgr.wonderful.utils;

import java.util.Calendar;
import java.util.Date;

public class DisplayUtils {
	public static final int ONE_MIN = 60;
	public static final int ONE_HOUR = 3600;
	
	private static final String TAG = "DisplayUtils";
	
	public static String transformTime(long timestamp){
		Calendar calendar = Calendar.getInstance();
		//状态发表的时间
		calendar.setTime(new Date(timestamp));
		int year1 = calendar.get(Calendar.YEAR);
		int month1 = calendar.get(Calendar.MONTH)+1 ;//从0开始，应该加1
		int dayOfMonth1= calendar.get(Calendar.DAY_OF_MONTH);
		int hour1 = calendar.get(Calendar.HOUR_OF_DAY) ;
		int minute1 = calendar.get(Calendar.MINUTE);
		LogUtils.i(TAG, "status:"+year1+" "+month1+" "+dayOfMonth1+" "+minute1);
		//现在的时间
		calendar.setTime(new Date());
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH)+1 ;//从0开始，应该加1
		int dayOfMonth= calendar.get(Calendar.DAY_OF_MONTH);
		int hour = calendar.get(Calendar.HOUR_OF_DAY) ;
		int minute = calendar.get(Calendar.MINUTE);
		LogUtils.i(TAG, "now"+year+" "+month+" "+dayOfMonth+" "+minute);
		
		String time = null;
		// 一般情况 下是满足这个 的
		if (year1 == year && month1 == month) {
			if (dayOfMonth1 == dayOfMonth) {
				// 今天
				if (hour1 == hour){
					if (minute-minute1==0){
						time = "刚刚";
					}else {
						time = (minute-minute1)+"分钟前";
					}
				}else {
					time =  hour1 + "点" + minute1+"分";
				}
			} else if (dayOfMonth - dayOfMonth1 == 1) {
				// 昨天
				time = "昨天" + hour1 +"点";
			} else {
				// 两天前，直接显示时间
				time = month1 + "月" + dayOfMonth1 + "日 " + hour1+"点";
			}
		} else {
			time = year1 + "年" + month1 + "月" + dayOfMonth1 + "日";
		}
		
		return time ;
	}
	
	public static String transformDistance(Long distance) {
		float distance1 = distance;
		float res = distance1/1000;
		if (res>=1){
			return "约"+(int)res+"千米";
		}else if (distance/100 >=1){ 
			return (int)(distance/100)+"00米" ;
		}else {
			return "100米左右" ;
		}
	}
	
	
}
